<?php
require_once ('libxmltv.php');
// file to save result`s
$xmlfile='tmp/test-xmltv.xml';

// init class XMLTV and send settings to the class
$xmltv = new XMLTV('1.0','utf-8','http://www.example.com/tvguide/','XMLTV/Generator wr. by Karpov S.M.','http://karpoff.zz.mu/xmltv-gen');

// array list channel`s
$c=count($data['channels']);
// looping channel array 
for ($i = 0; $i < $c; $i++) {
  // extract channels in array
	extract($data['channels'][$i]);
  // create tag channel in DOM object
  // You can create more
  $xmltv->CreateChannel($id);
  // set name channel an icon any more
	$xmltv->DisplayName($name,'ru',$id);
	$xmltv->Icon('img/'.$id.'.gif',$id);
  // clean extract names
	unset($id);
	unset($channel);
}

// array list channel`s
$p=count($data['programme']);
// looping programme array
for ($i = 0; $i < $p; $i++) {
  // extract programme in array
	extract($data['programme'][$i]);
  // create programe tag inDOM object
  // You can create more
  $xmltv->Programme( $start, $stop,$id,$i);
  // tag Title, you can create only one on the tag programme
	$xmltv->Title( $title,'ru',$i);
  // tag Credits, you can only one on the tag programme
  $xmltv->createCredits( $i);
  // tag Director and Actor and Writer, you can create any more in tag credits
  $xmltv->Director( $director, $i);
  $xmltv->Actor( $actor, $i);
  $xmltv->Writer( $writer, $i);
  // on the other tag read the specification on the format xmltv
  $xmltv->Country( $country, $i);
  $xmltv->Date( $date, $i);
  $xmltv->Episode( $episode_number, system, $i);
  // clean extract names
  unset($id);
	unset($start);
	unset($stop);
	unset($title);
}

// Compile tag`s
$xmltv->Compile('channel');
$xmltv->Compile('programme');

// If the file exists, remove it
if (@file_exists($xmlfile)) { unlink($xmlfile); }
// Save the result xml
file_put_contents($xmlfile, $xmltv->OutXMLTV(), FILE_APPEND | LOCK_EX);

?>